package LC03;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class LC0234 {
    public static void main(String[] args) {
        ListNode listNode2 = new ListNode(2);
        ListNode listNode1 = new ListNode(1);
        listNode1.next = listNode2;

        System.out.println(isPalindrome(listNode1));
    }

    public static boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        ListNode temp = head;
        while (temp != null) {
            list.add(temp.val);
            temp = temp.next;
        }

        int a = 0;
        int b = list.size() - 1;
        while (a <= b) {
            if (list.get(a) == list.get(b)) {
                a++;
                b--;
            } else {
                return false;
            }
        }

        return true;
    }
}
